import { defineStore } from "pinia";
import { useDark ,useToggle } from "@vueuse/core";

export const user =defineStore("user",{
    persist: {
        enabled: true,
        strategies: [
            { key: "userState", storage: localStorage },
        ],
    },
    state: ()=>{
        return{
            userId: 1
        };
    },
    getters:{
        getUserId: (state)=>{
            return state.userId
        }
    },
    actions:{
        setUserId(){
            this.userId ++;
        }
    }
})
 

export const articleStore=defineStore("article",{

    state: ()=>{
        return{
            article: {
                id:'',
                title:"",
                desc:"",
                banner:"",
                createTime:"",
                updateTime:"",
                views:"",
                likes:"",
                comments:'',
                tags:[],
                category:"",
                readDuration:""
            },
        };
    },
    getters:{
        getArticle() {
            return this.article
        }
    },
    actions:{
        setArticle(val){
            console.log(val);
            
             Object.assign(this.article,val)
            console.log(this.article);
        }
    }
})



const isDark = useDark();
const toggleDark = useToggle(isDark);

export const configStore =defineStore("config",{
    persist: {
        enabled: true,
        strategies: [
            { key: "confitState", storage: localStorage },
        ],
    },
    state: ()=>{
        return{
            isDark: isDark.value
        };
    },
    getters:{
        getIsDark(){
            return this.isDark;
        }
    },
    actions:{
        setToggleDark(){
        toggleDark.value = !toggleDark.value; // 修改 ref 的值来切换状态
            this.isDark = isDark.value; 
        
        }
    }
})